package com.leadership.training.entity.project;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;
import com.demo2do.core.format.PersistentFormat;
import com.leadership.entity.idm.Organization;
import com.leadership.training.entity.category.TrainingCategory;


/**
 * 培训项目
 * 
 * @author Rockett
 *
 */
@Entity
@Table(name = "t_project")
public class Project {
    
	/**
	 * ID
	 */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 项目名称
     */
    private String name;
    
    /**
     * 项目编号
     */
    private String code;
    
    /**
     * 一级分类
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private TrainingCategory firstCategory;
    
    /**
     * 二级分类
     */
    @PersistentFormat
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private TrainingCategory secondCategory;
    
    /**
     * 期数
     */
    private int phaseCount;
    
    /**
     * 项目负责人
     * 
     */
    private String projectLead;
    
    private String projectLeadEmail;
    
    private String umuType;
    
    private String umuLink;

    /**
     * 部门
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Organization organization;

    /**
     * 
     */
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 开始日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date beginDate;

    /**
     * 结束日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date endDate;
    
    /**
     * 创建日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    
    /**
     * 状态
     */
    private String status;
    
    /**
     * 创建人
     */
    private Long operator;
    
    /**
     * 
     */
    @Column(name = "finished_result")
    private boolean finishedResult;
    
    /**
     * 是否归档
     */
    @Column(name = "is_saved")
    private boolean saved;
    
    /**
     * 
     */
    @Column(name = "finished_survey")
    private boolean finishedSurvey;

	/**
     * The default constructor
     */
    public Project() {
    	this.disabled=false;
    	this.status = "课程添加未完成";
    }
    
    public Project(Project oldProject) {
        this.name = oldProject.getName();
        this.code = "p" + new Date().getTime();
        this.firstCategory = oldProject.getFirstCategory();
        this.secondCategory = oldProject.getSecondCategory();
        this.phaseCount = oldProject.getPhaseCount();
        this.projectLead = oldProject.getProjectLead();
        this.projectLeadEmail = oldProject.getProjectLeadEmail();
        this.organization = oldProject.getOrganization();
        this.disabled = false;
        this.beginDate = oldProject.getBeginDate();
        this.endDate = oldProject.getEndDate();
        this.createTime = new Date();
    }
    
    /**
     * @param name
     */
    public Project(String name) {
        this.id = new Long(1);
        this.name = name;
        this.disabled = false;
    }
    
    /**
     * 
     * @param date
     * @param projectLead
     * @return
     */
	public Project init(Long opLong, Date date){
		this.code ="p" + new Date().getTime();
		this.createTime=date;
		this.operator = opLong;
		return this;
	}

    
    /**
     * @param firstCategory
     * @param secondCategory
     * @param department
     * @param date
     * @return
     */
    public Project initialize(TrainingCategory firstCategory, TrainingCategory secondCategory, Organization organization, Date date) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        this.organization = organization;
        this.createTime = date;
        return this;
    }
    
    /**
     * 
     * @param minDate
     * @param maxDate
     * @return
     */
    public Project editDate(Date minDate, Date maxDate) {
    	this.beginDate = minDate;
    	this.endDate = maxDate;
    	return this;
    }
    
    public Project editUmu(String umuType, String umuLink) {
        this.umuType = umuType;
        this.umuLink = umuLink;
        return this;
    }
    
    /**
     * @param firstCategory
     * @param secondCategory
     * @param department
     * @return
     */
    public Project editInfo(TrainingCategory firstCategory, TrainingCategory secondCategory, Organization organization) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        this.organization = organization;
        return this;
    }
    
    /**
     * @param firstCategory
     * @param secondCategory
     * @return
     */
    public Project update(TrainingCategory firstCategory, TrainingCategory secondCategory) {
        this.firstCategory = firstCategory;
        this.secondCategory = secondCategory;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the firstCategory
     */
    public TrainingCategory getFirstCategory() {
        return firstCategory;
    }

    /**
     * @return the secondCategory
     */
    public TrainingCategory getSecondCategory() {
        return secondCategory;
    }

    /**
     * @return the phaseCount
     */
    public int getPhaseCount() {
        return phaseCount;
    }

    /**
     * @return the projectLead
     */
    public String getProjectLead() {
        return projectLead;
    }

    /**
     * @return the projectLeadEmail
     */
    public String getProjectLeadEmail() {
        return projectLeadEmail;
    }

    /**
     * @return the umuType
     */
    public String getUmuType() {
        return umuType;
    }

    /**
     * @return the umuLink
     */
    public String getUmuLink() {
        return umuLink;
    }

    /**
     * @return the organization
     */
    public Organization getOrganization() {
        return organization;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }
    
    public boolean isSaved() {
        return saved;
    }

    /**
     * @return the beginDate
     */
    public Date getBeginDate() {
        return beginDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @return the finishedResult
     */
    public boolean isFinishedResult() {
        return finishedResult;
    }

    /**
     * @return the finishedSurvey
     */
    public boolean isFinishedSurvey() {
        return finishedSurvey;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param firstCategory the firstCategory to set
     */
    public void setFirstCategory(TrainingCategory firstCategory) {
        this.firstCategory = firstCategory;
    }

    /**
     * @param secondCategory the secondCategory to set
     */
    public void setSecondCategory(TrainingCategory secondCategory) {
        this.secondCategory = secondCategory;
    }

    /**
     * @param phaseCount the phaseCount to set
     */
    public void setPhaseCount(int phaseCount) {
        this.phaseCount = phaseCount;
    }

    /**
     * @param projectLead the projectLead to set
     */
    public void setProjectLead(String projectLead) {
        this.projectLead = projectLead;
    }

    /**
     * @param projectLeadEmail the projectLeadEmail to set
     */
    public void setProjectLeadEmail(String projectLeadEmail) {
        this.projectLeadEmail = projectLeadEmail;
    }

    /**
     * @param umuType the umuType to set
     */
    public void setUmuType(String umuType) {
        this.umuType = umuType;
    }

    /**
     * @param umuLink the umuLink to set
     */
    public void setUmuLink(String umuLink) {
        this.umuLink = umuLink;
    }

    /**
     * @param organization the organization to set
     */
    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
    public void setSaved(boolean saved) {
        this.saved = saved;
    }

    /**
     * @param beginDate the beginDate to set
     */
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @param finishedResult the finishedResult to set
     */
    public void setFinishedResult(boolean finishedResult) {
        this.finishedResult = finishedResult;
    }

    /**
     * @param finishedSurvey the finishedSurvey to set
     */
    public void setFinishedSurvey(boolean finishedSurvey) {
        this.finishedSurvey = finishedSurvey;
    }
    
    public Long getOperator() {
        return operator;
    }
    
    public void setOperator(Long operator) {
        this.operator = operator;
    }

}